package com.isoftstone.app.controller.banner;

import com.isoftstone.bank.controller.base.BaseController;
import com.isoftstone.bank.entity.PAd;
import com.isoftstone.bank.service.IPAdService;
import com.isoftstone.common.Tidings;
import com.isoftstone.util.Const;
import com.isoftstone.util.PropertiesUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: zhaojg
 * @Description
 * @Date: Created in 16:46 2017/12/26
 * @Modified by:
 * <p>
 * 手机端轮播图接口
 */

@Controller
public class BannerController extends BaseController {

    @Autowired
    private IPAdService service;

    @RequestMapping(value = "app/queryBanner", method = RequestMethod.POST)
    @ResponseBody
    public Tidings<Map<String, Object>> queryBanner() {

        Tidings<Map<String, Object>> tidings = new Tidings<Map<String, Object>>();
        Map<String, Object> reMap = new HashMap<String, Object>();
        List<PAd> pAdList = null;
        try {
            pAdList = service.getPAdList();
            if (pAdList.size() > 0) {
                for (PAd pAd : pAdList) {
                    String adFilePath = pAd.getAdFilePath();
                    if (adFilePath != null) {
                        String path = PropertiesUtils.getProperties("baseContextPath") + Const.FILEPATHIMG + adFilePath;
                        pAd.setAdFilePath(path);
                    }
                }
                reMap.put("pAdList", pAdList);
                tidings.setMsg("查询成功");
                tidings.setStatus(Const.SUCCESS);
                tidings.setT(reMap);
            } else {
                tidings.setMsg("没有查询到数据");
                tidings.setStatus(Const.TPBCZ);
            }
        } catch (Exception e) {
            e.printStackTrace();
            tidings.setMsg("查询失败");
            tidings.setStatus(Const.ERROR);
        }
        return tidings;
    }
}
